<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>main.cpp 示例文件 | Qt Widgets 5.12.3</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td ><a href="../qtdoc/index.html">Qt 5.12</a></td><td ><a href="qtwidgets-index.html">Qt Widgets</a></td><td ><a href="qtwidgets-animation-animatedtiles-example.html">Animated Tiles Example</a></td><td >main.cpp 示例文件</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right"><a href="qtwidgets-index.html">Qt 5.12.3 参考指南</a></td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar"><div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">main.cpp 示例文件</h1>
<span class="subtitle">animation/animatedtiles/main.cpp</span>
<!-- $$$animation/animatedtiles/main.cpp-description -->
<div class="descr"> <a name="details"></a>
<pre class="cpp">

  <span class="comment">/****************************************************************************
  **
  ** Copyright (C) 2016 The Qt Company Ltd.
  ** Contact: https://www.qt.io/licensing/
  **
  ** This file is part of the QtCore module of the Qt Toolkit.
  **
  ** $QT_BEGIN_LICENSE:BSD$
  ** Commercial License Usage
  ** Licensees holding valid commercial Qt licenses may use this file in
  ** accordance with the commercial license agreement provided with the
  ** Software or, alternatively, in accordance with the terms contained in
  ** a written agreement between you and The Qt Company. For licensing terms
  ** and conditions see https://www.qt.io/terms-conditions. For further
  ** information use the contact form at https://www.qt.io/contact-us.
  **
  ** BSD License Usage
  ** Alternatively, you may use this file under the terms of the BSD license
  ** as follows:
  **
  ** &quot;Redistribution and use in source and binary forms, with or without
  ** modification, are permitted provided that the following conditions are
  ** met:
  **   * Redistributions of source code must retain the above copyright
  **     notice, this list of conditions and the following disclaimer.
  **   * Redistributions in binary form must reproduce the above copyright
  **     notice, this list of conditions and the following disclaimer in
  **     the documentation and/or other materials provided with the
  **     distribution.
  **   * Neither the name of The Qt Company Ltd nor the names of its
  **     contributors may be used to endorse or promote products derived
  **     from this software without specific prior written permission.
  **
  **
  ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  ** &quot;AS IS&quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.&quot;
  **
  ** $QT_END_LICENSE$
  **
  ****************************************************************************/</span>

  <span class="preprocessor">#include &lt;QtWidgets/QtWidgets&gt;</span>
  <span class="preprocessor">#include &lt;QtCore/qmath.h&gt;</span>
  <span class="preprocessor">#include &lt;QtCore/qrandom.h&gt;</span>
  <span class="preprocessor">#include &lt;QtCore/qstate.h&gt;</span>

  <span class="keyword">class</span> Pixmap : <span class="keyword">public</span> <span class="type"><a href="../qtcore/qobject.html">QObject</a></span><span class="operator">,</span> <span class="keyword">public</span> <span class="type"><a href="qgraphicspixmapitem.html">QGraphicsPixmapItem</a></span>
  {
      Q_OBJECT
      Q_PROPERTY(<span class="type"><a href="../qtcore/qpointf.html">QPointF</a></span> pos READ pos WRITE setPos)
  <span class="keyword">public</span>:
      Pixmap(<span class="keyword">const</span> <span class="type"><a href="../qtgui/qpixmap.html">QPixmap</a></span> <span class="operator">&amp;</span>pix)
          : <span class="type"><a href="../qtcore/qobject.html">QObject</a></span>()<span class="operator">,</span> <span class="type"><a href="qgraphicspixmapitem.html">QGraphicsPixmapItem</a></span>(pix)
      {
          setCacheMode(DeviceCoordinateCache);
      }
  };

  <span class="keyword">class</span> Button : <span class="keyword">public</span> <span class="type"><a href="qgraphicswidget.html">QGraphicsWidget</a></span>
  {
      Q_OBJECT
  <span class="keyword">public</span>:
      Button(<span class="keyword">const</span> <span class="type"><a href="../qtgui/qpixmap.html">QPixmap</a></span> <span class="operator">&amp;</span>pixmap<span class="operator">,</span> <span class="type"><a href="qgraphicsitem.html">QGraphicsItem</a></span> <span class="operator">*</span>parent <span class="operator">=</span> <span class="number">0</span>)
          : <span class="type"><a href="qgraphicswidget.html">QGraphicsWidget</a></span>(parent)<span class="operator">,</span> _pix(pixmap)
      {
          setAcceptHoverEvents(<span class="keyword">true</span>);
          setCacheMode(DeviceCoordinateCache);
      }

      <span class="type"><a href="../qtcore/qrectf.html">QRectF</a></span> boundingRect() <span class="keyword">const</span> override
      {
          <span class="keyword">return</span> <span class="type"><a href="../qtcore/qrectf.html">QRectF</a></span>(<span class="operator">-</span><span class="number">65</span><span class="operator">,</span> <span class="operator">-</span><span class="number">65</span><span class="operator">,</span> <span class="number">130</span><span class="operator">,</span> <span class="number">130</span>);
      }

      <span class="type"><a href="../qtgui/qpainterpath.html">QPainterPath</a></span> shape() <span class="keyword">const</span> override
      {
          <span class="type"><a href="../qtgui/qpainterpath.html">QPainterPath</a></span> path;
          path<span class="operator">.</span>addEllipse(boundingRect());
          <span class="keyword">return</span> path;
      }

      <span class="type">void</span> paint(<span class="type"><a href="../qtgui/qpainter.html">QPainter</a></span> <span class="operator">*</span>painter<span class="operator">,</span> <span class="keyword">const</span> <span class="type"><a href="qstyleoptiongraphicsitem.html">QStyleOptionGraphicsItem</a></span> <span class="operator">*</span>option<span class="operator">,</span> <span class="type"><a href="qwidget.html">QWidget</a></span> <span class="operator">*</span>) override
      {
          bool down <span class="operator">=</span> option<span class="operator">-</span><span class="operator">&gt;</span>state <span class="operator">&amp;</span> <span class="type"><a href="qstyle.html">QStyle</a></span><span class="operator">::</span>State_Sunken;
          <span class="type"><a href="../qtcore/qrectf.html">QRectF</a></span> r <span class="operator">=</span> boundingRect();
          <span class="type"><a href="../qtgui/qlineargradient.html">QLinearGradient</a></span> grad(r<span class="operator">.</span>topLeft()<span class="operator">,</span> r<span class="operator">.</span>bottomRight());
          grad<span class="operator">.</span>setColorAt(down <span class="operator">?</span> <span class="number">1</span> : <span class="number">0</span><span class="operator">,</span> option<span class="operator">-</span><span class="operator">&gt;</span>state <span class="operator">&amp;</span> <span class="type"><a href="qstyle.html">QStyle</a></span><span class="operator">::</span>State_MouseOver <span class="operator">?</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>white : <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>lightGray);
          grad<span class="operator">.</span>setColorAt(down <span class="operator">?</span> <span class="number">0</span> : <span class="number">1</span><span class="operator">,</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>darkGray);
          painter<span class="operator">-</span><span class="operator">&gt;</span>setPen(<span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>darkGray);
          painter<span class="operator">-</span><span class="operator">&gt;</span>setBrush(grad);
          painter<span class="operator">-</span><span class="operator">&gt;</span>drawEllipse(r);
          <span class="type"><a href="../qtgui/qlineargradient.html">QLinearGradient</a></span> grad2(r<span class="operator">.</span>topLeft()<span class="operator">,</span> r<span class="operator">.</span>bottomRight());
          grad<span class="operator">.</span>setColorAt(down <span class="operator">?</span> <span class="number">1</span> : <span class="number">0</span><span class="operator">,</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>darkGray);
          grad<span class="operator">.</span>setColorAt(down <span class="operator">?</span> <span class="number">0</span> : <span class="number">1</span><span class="operator">,</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>lightGray);
          painter<span class="operator">-</span><span class="operator">&gt;</span>setPen(<span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>NoPen);
          painter<span class="operator">-</span><span class="operator">&gt;</span>setBrush(grad);
          <span class="keyword">if</span> (down)
              painter<span class="operator">-</span><span class="operator">&gt;</span>translate(<span class="number">2</span><span class="operator">,</span> <span class="number">2</span>);
          painter<span class="operator">-</span><span class="operator">&gt;</span>drawEllipse(r<span class="operator">.</span>adjusted(<span class="number">5</span><span class="operator">,</span> <span class="number">5</span><span class="operator">,</span> <span class="operator">-</span><span class="number">5</span><span class="operator">,</span> <span class="operator">-</span><span class="number">5</span>));
          painter<span class="operator">-</span><span class="operator">&gt;</span>drawPixmap(<span class="operator">-</span>_pix<span class="operator">.</span>width()<span class="operator">/</span><span class="number">2</span><span class="operator">,</span> <span class="operator">-</span>_pix<span class="operator">.</span>height()<span class="operator">/</span><span class="number">2</span><span class="operator">,</span> _pix);
      }

  <span class="keyword">signals</span>:
      <span class="type">void</span> pressed();

  <span class="keyword">protected</span>:
      <span class="type">void</span> mousePressEvent(<span class="type"><a href="qgraphicsscenemouseevent.html">QGraphicsSceneMouseEvent</a></span> <span class="operator">*</span>) override
      {
          <span class="keyword">emit</span> pressed();
          update();
      }

      <span class="type">void</span> mouseReleaseEvent(<span class="type"><a href="qgraphicsscenemouseevent.html">QGraphicsSceneMouseEvent</a></span> <span class="operator">*</span>) override
      {
          update();
      }

  <span class="keyword">private</span>:
      <span class="type"><a href="../qtgui/qpixmap.html">QPixmap</a></span> _pix;
  };

  <span class="keyword">class</span> View : <span class="keyword">public</span> <span class="type"><a href="qgraphicsview.html">QGraphicsView</a></span>
  {
  <span class="keyword">public</span>:
      View(<span class="type"><a href="qgraphicsscene.html">QGraphicsScene</a></span> <span class="operator">*</span>scene) : <span class="type"><a href="qgraphicsview.html">QGraphicsView</a></span>(scene) { }

  <span class="keyword">protected</span>:
      <span class="type">void</span> resizeEvent(<span class="type"><a href="../qtgui/qresizeevent.html">QResizeEvent</a></span> <span class="operator">*</span>event) override
      {
          <span class="type"><a href="qgraphicsview.html">QGraphicsView</a></span><span class="operator">::</span>resizeEvent(event);
          fitInView(sceneRect()<span class="operator">,</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>KeepAspectRatio);
      }
  };

  <span class="type">int</span> main(<span class="type">int</span> argc<span class="operator">,</span> <span class="type">char</span> <span class="operator">*</span><span class="operator">*</span>argv)
  {
      Q_INIT_RESOURCE(animatedtiles);

      <span class="type"><a href="qapplication.html">QApplication</a></span> app(argc<span class="operator">,</span> argv);

      <span class="type"><a href="../qtgui/qpixmap.html">QPixmap</a></span> kineticPix(<span class="string">&quot;:/images/kinetic.png&quot;</span>);
      <span class="type"><a href="../qtgui/qpixmap.html">QPixmap</a></span> bgPix(<span class="string">&quot;:/images/Time-For-Lunch-2.jpg&quot;</span>);

      <span class="type"><a href="qgraphicsscene.html">QGraphicsScene</a></span> scene(<span class="operator">-</span><span class="number">350</span><span class="operator">,</span> <span class="operator">-</span><span class="number">350</span><span class="operator">,</span> <span class="number">700</span><span class="operator">,</span> <span class="number">700</span>);

      <span class="type"><a href="../qtcore/qlist.html">QList</a></span><span class="operator">&lt;</span>Pixmap <span class="operator">*</span><span class="operator">&gt;</span> items;
      <span class="keyword">for</span> (<span class="type">int</span> i <span class="operator">=</span> <span class="number">0</span>; i <span class="operator">&lt;</span> <span class="number">64</span>; <span class="operator">+</span><span class="operator">+</span>i) {
          Pixmap <span class="operator">*</span>item <span class="operator">=</span> <span class="keyword">new</span> Pixmap(kineticPix);
          item<span class="operator">-</span><span class="operator">&gt;</span>setOffset(<span class="operator">-</span>kineticPix<span class="operator">.</span>width()<span class="operator">/</span><span class="number">2</span><span class="operator">,</span> <span class="operator">-</span>kineticPix<span class="operator">.</span>height()<span class="operator">/</span><span class="number">2</span>);
          item<span class="operator">-</span><span class="operator">&gt;</span>setZValue(i);
          items <span class="operator">&lt;</span><span class="operator">&lt;</span> item;
          scene<span class="operator">.</span>addItem(item);
      }

      <span class="comment">// Buttons</span>
      <span class="type"><a href="qgraphicsitem.html">QGraphicsItem</a></span> <span class="operator">*</span>buttonParent <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qgraphicsrectitem.html">QGraphicsRectItem</a></span>;
      Button <span class="operator">*</span>ellipseButton <span class="operator">=</span> <span class="keyword">new</span> Button(<span class="type"><a href="../qtgui/qpixmap.html">QPixmap</a></span>(<span class="string">&quot;:/images/ellipse.png&quot;</span>)<span class="operator">,</span> buttonParent);
      Button <span class="operator">*</span>figure8Button <span class="operator">=</span> <span class="keyword">new</span> Button(<span class="type"><a href="../qtgui/qpixmap.html">QPixmap</a></span>(<span class="string">&quot;:/images/figure8.png&quot;</span>)<span class="operator">,</span> buttonParent);
      Button <span class="operator">*</span>randomButton <span class="operator">=</span> <span class="keyword">new</span> Button(<span class="type"><a href="../qtgui/qpixmap.html">QPixmap</a></span>(<span class="string">&quot;:/images/random.png&quot;</span>)<span class="operator">,</span> buttonParent);
      Button <span class="operator">*</span>tiledButton <span class="operator">=</span> <span class="keyword">new</span> Button(<span class="type"><a href="../qtgui/qpixmap.html">QPixmap</a></span>(<span class="string">&quot;:/images/tile.png&quot;</span>)<span class="operator">,</span> buttonParent);
      Button <span class="operator">*</span>centeredButton <span class="operator">=</span> <span class="keyword">new</span> Button(<span class="type"><a href="../qtgui/qpixmap.html">QPixmap</a></span>(<span class="string">&quot;:/images/centered.png&quot;</span>)<span class="operator">,</span> buttonParent);

      ellipseButton<span class="operator">-</span><span class="operator">&gt;</span>setPos(<span class="operator">-</span><span class="number">100</span><span class="operator">,</span> <span class="operator">-</span><span class="number">100</span>);
      figure8Button<span class="operator">-</span><span class="operator">&gt;</span>setPos(<span class="number">100</span><span class="operator">,</span> <span class="operator">-</span><span class="number">100</span>);
      randomButton<span class="operator">-</span><span class="operator">&gt;</span>setPos(<span class="number">0</span><span class="operator">,</span> <span class="number">0</span>);
      tiledButton<span class="operator">-</span><span class="operator">&gt;</span>setPos(<span class="operator">-</span><span class="number">100</span><span class="operator">,</span> <span class="number">100</span>);
      centeredButton<span class="operator">-</span><span class="operator">&gt;</span>setPos(<span class="number">100</span><span class="operator">,</span> <span class="number">100</span>);

      scene<span class="operator">.</span>addItem(buttonParent);
      buttonParent<span class="operator">-</span><span class="operator">&gt;</span>setTransform(<span class="type"><a href="../qtgui/qtransform.html">QTransform</a></span><span class="operator">::</span>fromScale(<span class="number">0.75</span><span class="operator">,</span> <span class="number">0.75</span>)<span class="operator">,</span> <span class="keyword">true</span>);
      buttonParent<span class="operator">-</span><span class="operator">&gt;</span>setPos(<span class="number">200</span><span class="operator">,</span> <span class="number">200</span>);
      buttonParent<span class="operator">-</span><span class="operator">&gt;</span>setZValue(<span class="number">65</span>);

      <span class="comment">// States</span>
      <span class="type"><a href="../qtcore/qstate.html">QState</a></span> <span class="operator">*</span>rootState <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="../qtcore/qstate.html">QState</a></span>;
      <span class="type"><a href="../qtcore/qstate.html">QState</a></span> <span class="operator">*</span>ellipseState <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="../qtcore/qstate.html">QState</a></span>(rootState);
      <span class="type"><a href="../qtcore/qstate.html">QState</a></span> <span class="operator">*</span>figure8State <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="../qtcore/qstate.html">QState</a></span>(rootState);
      <span class="type"><a href="../qtcore/qstate.html">QState</a></span> <span class="operator">*</span>randomState <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="../qtcore/qstate.html">QState</a></span>(rootState);
      <span class="type"><a href="../qtcore/qstate.html">QState</a></span> <span class="operator">*</span>tiledState <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="../qtcore/qstate.html">QState</a></span>(rootState);
      <span class="type"><a href="../qtcore/qstate.html">QState</a></span> <span class="operator">*</span>centeredState <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="../qtcore/qstate.html">QState</a></span>(rootState);

      <span class="comment">// Values</span>
      <span class="keyword">for</span> (<span class="type">int</span> i <span class="operator">=</span> <span class="number">0</span>; i <span class="operator">&lt;</span> items<span class="operator">.</span>count(); <span class="operator">+</span><span class="operator">+</span>i) {
          Pixmap <span class="operator">*</span>item <span class="operator">=</span> items<span class="operator">.</span>at(i);
          <span class="comment">// Ellipse</span>
          ellipseState<span class="operator">-</span><span class="operator">&gt;</span>assignProperty(item<span class="operator">,</span> <span class="string">&quot;pos&quot;</span><span class="operator">,</span>
                                           <span class="type"><a href="../qtcore/qpointf.html">QPointF</a></span>(<a href="../qtcore/qtmath.html#qCos">qCos</a>((i <span class="operator">/</span> <span class="number">63.0</span>) <span class="operator">*</span> <span class="number">6.28</span>) <span class="operator">*</span> <span class="number">250</span><span class="operator">,</span>
                                                   <a href="../qtcore/qtmath.html#qSin">qSin</a>((i <span class="operator">/</span> <span class="number">63.0</span>) <span class="operator">*</span> <span class="number">6.28</span>) <span class="operator">*</span> <span class="number">250</span>));

          <span class="comment">// Figure 8</span>
          figure8State<span class="operator">-</span><span class="operator">&gt;</span>assignProperty(item<span class="operator">,</span> <span class="string">&quot;pos&quot;</span><span class="operator">,</span>
                                           <span class="type"><a href="../qtcore/qpointf.html">QPointF</a></span>(<a href="../qtcore/qtmath.html#qSin">qSin</a>((i <span class="operator">/</span> <span class="number">63.0</span>) <span class="operator">*</span> <span class="number">6.28</span>) <span class="operator">*</span> <span class="number">250</span><span class="operator">,</span>
                                                   <a href="../qtcore/qtmath.html#qSin">qSin</a>(((i <span class="operator">*</span> <span class="number">2</span>)<span class="operator">/</span><span class="number">63.0</span>) <span class="operator">*</span> <span class="number">6.28</span>) <span class="operator">*</span> <span class="number">250</span>));

          <span class="comment">// Random</span>
          randomState<span class="operator">-</span><span class="operator">&gt;</span>assignProperty(item<span class="operator">,</span> <span class="string">&quot;pos&quot;</span><span class="operator">,</span>
                                          <span class="type"><a href="../qtcore/qpointf.html">QPointF</a></span>(<span class="operator">-</span><span class="number">250</span> <span class="operator">+</span> <span class="type"><a href="../qtcore/qrandomgenerator.html">QRandomGenerator</a></span><span class="operator">::</span>global()<span class="operator">-</span><span class="operator">&gt;</span>bounded(<span class="number">500</span>)<span class="operator">,</span>
                                                  <span class="operator">-</span><span class="number">250</span> <span class="operator">+</span> <span class="type"><a href="../qtcore/qrandomgenerator.html">QRandomGenerator</a></span><span class="operator">::</span>global()<span class="operator">-</span><span class="operator">&gt;</span>bounded(<span class="number">500</span>)));

          <span class="comment">// Tiled</span>
          tiledState<span class="operator">-</span><span class="operator">&gt;</span>assignProperty(item<span class="operator">,</span> <span class="string">&quot;pos&quot;</span><span class="operator">,</span>
                                         <span class="type"><a href="../qtcore/qpointf.html">QPointF</a></span>(((i <span class="operator">%</span> <span class="number">8</span>) <span class="operator">-</span> <span class="number">4</span>) <span class="operator">*</span> kineticPix<span class="operator">.</span>width() <span class="operator">+</span> kineticPix<span class="operator">.</span>width() <span class="operator">/</span> <span class="number">2</span><span class="operator">,</span>
                                                 ((i <span class="operator">/</span> <span class="number">8</span>) <span class="operator">-</span> <span class="number">4</span>) <span class="operator">*</span> kineticPix<span class="operator">.</span>height() <span class="operator">+</span> kineticPix<span class="operator">.</span>height() <span class="operator">/</span> <span class="number">2</span>));

          <span class="comment">// Centered</span>
          centeredState<span class="operator">-</span><span class="operator">&gt;</span>assignProperty(item<span class="operator">,</span> <span class="string">&quot;pos&quot;</span><span class="operator">,</span> <span class="type"><a href="../qtcore/qpointf.html">QPointF</a></span>());
      }

      <span class="comment">// Ui</span>
      View <span class="operator">*</span>view <span class="operator">=</span> <span class="keyword">new</span> View(<span class="operator">&amp;</span>scene);
      view<span class="operator">-</span><span class="operator">&gt;</span>setWindowTitle(QT_TRANSLATE_NOOP(<span class="type"><a href="qgraphicsview.html">QGraphicsView</a></span><span class="operator">,</span> <span class="string">&quot;Animated Tiles&quot;</span>));
      view<span class="operator">-</span><span class="operator">&gt;</span>setViewportUpdateMode(<span class="type"><a href="qgraphicsview.html">QGraphicsView</a></span><span class="operator">::</span>BoundingRectViewportUpdate);
      view<span class="operator">-</span><span class="operator">&gt;</span>setBackgroundBrush(bgPix);
      view<span class="operator">-</span><span class="operator">&gt;</span>setCacheMode(<span class="type"><a href="qgraphicsview.html">QGraphicsView</a></span><span class="operator">::</span>CacheBackground);
      view<span class="operator">-</span><span class="operator">&gt;</span>setRenderHints(<span class="type"><a href="../qtgui/qpainter.html">QPainter</a></span><span class="operator">::</span>Antialiasing <span class="operator">|</span> <span class="type"><a href="../qtgui/qpainter.html">QPainter</a></span><span class="operator">::</span>SmoothPixmapTransform);
      view<span class="operator">-</span><span class="operator">&gt;</span>show();

      <span class="type"><a href="../qtcore/qstatemachine.html">QStateMachine</a></span> states;
      states<span class="operator">.</span>addState(rootState);
      states<span class="operator">.</span>setInitialState(rootState);
      rootState<span class="operator">-</span><span class="operator">&gt;</span>setInitialState(centeredState);

      <span class="type"><a href="../qtcore/qparallelanimationgroup.html">QParallelAnimationGroup</a></span> <span class="operator">*</span>group <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="../qtcore/qparallelanimationgroup.html">QParallelAnimationGroup</a></span>;
      <span class="keyword">for</span> (<span class="type">int</span> i <span class="operator">=</span> <span class="number">0</span>; i <span class="operator">&lt;</span> items<span class="operator">.</span>count(); <span class="operator">+</span><span class="operator">+</span>i) {
          <span class="type"><a href="../qtcore/qpropertyanimation.html">QPropertyAnimation</a></span> <span class="operator">*</span>anim <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="../qtcore/qpropertyanimation.html">QPropertyAnimation</a></span>(items<span class="operator">[</span>i<span class="operator">]</span><span class="operator">,</span> <span class="string">&quot;pos&quot;</span>);
          anim<span class="operator">-</span><span class="operator">&gt;</span>setDuration(<span class="number">750</span> <span class="operator">+</span> i <span class="operator">*</span> <span class="number">25</span>);
          anim<span class="operator">-</span><span class="operator">&gt;</span>setEasingCurve(<span class="type"><a href="../qtcore/qeasingcurve.html">QEasingCurve</a></span><span class="operator">::</span>InOutBack);
          group<span class="operator">-</span><span class="operator">&gt;</span>addAnimation(anim);
      }
      <span class="type"><a href="../qtcore/qabstracttransition.html">QAbstractTransition</a></span> <span class="operator">*</span>trans <span class="operator">=</span> rootState<span class="operator">-</span><span class="operator">&gt;</span>addTransition(ellipseButton<span class="operator">,</span> <span class="operator">&amp;</span>Button<span class="operator">::</span>pressed<span class="operator">,</span> ellipseState);
      trans<span class="operator">-</span><span class="operator">&gt;</span>addAnimation(group);

      trans <span class="operator">=</span> rootState<span class="operator">-</span><span class="operator">&gt;</span>addTransition(figure8Button<span class="operator">,</span> <span class="operator">&amp;</span>Button<span class="operator">::</span>pressed<span class="operator">,</span> figure8State);
      trans<span class="operator">-</span><span class="operator">&gt;</span>addAnimation(group);

      trans <span class="operator">=</span> rootState<span class="operator">-</span><span class="operator">&gt;</span>addTransition(randomButton<span class="operator">,</span> <span class="operator">&amp;</span>Button<span class="operator">::</span>pressed<span class="operator">,</span> randomState);
      trans<span class="operator">-</span><span class="operator">&gt;</span>addAnimation(group);

      trans <span class="operator">=</span> rootState<span class="operator">-</span><span class="operator">&gt;</span>addTransition(tiledButton<span class="operator">,</span> <span class="operator">&amp;</span>Button<span class="operator">::</span>pressed<span class="operator">,</span> tiledState);
      trans<span class="operator">-</span><span class="operator">&gt;</span>addAnimation(group);

      trans <span class="operator">=</span> rootState<span class="operator">-</span><span class="operator">&gt;</span>addTransition(centeredButton<span class="operator">,</span> <span class="operator">&amp;</span>Button<span class="operator">::</span>pressed<span class="operator">,</span> centeredState);
      trans<span class="operator">-</span><span class="operator">&gt;</span>addAnimation(group);

      <span class="type"><a href="../qtcore/qtimer.html">QTimer</a></span> timer;
      timer<span class="operator">.</span>start(<span class="number">125</span>);
      timer<span class="operator">.</span>setSingleShot(<span class="keyword">true</span>);
      trans <span class="operator">=</span> rootState<span class="operator">-</span><span class="operator">&gt;</span>addTransition(<span class="operator">&amp;</span>timer<span class="operator">,</span> <span class="operator">&amp;</span><span class="type"><a href="../qtcore/qtimer.html">QTimer</a></span><span class="operator">::</span>timeout<span class="operator">,</span> ellipseState);
      trans<span class="operator">-</span><span class="operator">&gt;</span>addAnimation(group);

      states<span class="operator">.</span>start();

  <span class="preprocessor">#ifdef QT_KEYPAD_NAVIGATION</span>
      <span class="type"><a href="qapplication.html">QApplication</a></span><span class="operator">::</span>setNavigationMode(<span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>NavigationModeCursorAuto);
  <span class="preprocessor">#endif</span>
      <span class="keyword">return</span> app<span class="operator">.</span>exec();
  }

  <span class="preprocessor">#include &quot;main.moc&quot;</span>

</pre>
</div>
<!-- @@@animation/animatedtiles/main.cpp -->
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2019 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br/>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br/>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>
